<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
       
    </style>
</head>
<body>
    <div id="app">
        <h2>{{firstName + ' '+ lastName}}</h2>
        <!--计算属性-->
        <h2>{{fullName}}</h2>
        <h2>{{totalPrice}}</h2>
    </div>
    <script src="../js/vue.js">
    </script>
    <script>
        const app=new Vue({
            el:'#app',
            data:{
                firstName:'hurna',
                lastName:'chenlong',
                books:[
                {id:100,name:"java",price:100},
                {id:101,name:"c",price:200},
                {id:102,name:"hadoop",price:300},
                ]       
            },
            //计算属性  有缓存的功能
            computed:{
                //计算属性 get set
                    fullName:function(){
                        return this.firstName+this.lastName
                    },
                    totalPrice:function(){
                        let result = 0
                       for(let i=0;i<this.books.length;i++){
                        result+=this.books[i].price
                       }
                       return result
                    },
                    //计算属性 get setter
                   fullName2:{
                    set:function(newValue){
                        console.log("-----------------",newValue)
                    },
                    get:function(){
                        return this.firstName+this.lastName
                    }
                   }

            },
            methods:{
                getFullName:function(){
                    return this.firstName+this.lastName
                }
            }
        })
    </script>
</body>
</html>